package Controller;


import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JTextArea;

import View.ManagerView;


public class ManagerController {
	private ManagerView view = null;
	private JFrame frame;
	private JInternalFrame iframe = null;
	
	public ManagerController(){
		view = new ManagerView();
		frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		doAction();
		frame.add(view);
		Dimension screensize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		frame.setBounds(screensize.width/2-400,screensize.height/2 - 300,800,600);
		frame.setVisible(true);
//		iframe = new JInternalFrame("Search Transfer",true);
//		iframe.setSize(700, 450);
//		iframe.getContentPane().add(new SearchController().getView());
//		iframe.setVisible(true);
//		view.addFrame(iframe);
		
	}
	
	private void doAction(){
		doNew();
		doSearch();
		doRequest();
		doSystem();
		doExit();
	}
	private void doNew(){
		view.doNew(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if (iframe!= null) iframe.dispose();
				iframe = new MakeNewController().getFrame();
				view.addFrame(iframe);
			}
		});
	}
	private void doSearch(){
		view.doSearch(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if (iframe!= null) iframe.dispose();
				iframe = new SearchController().getFrame();
				view.addFrame(iframe);
			}
		});
	}
	private void doRequest(){
		view.doRequest(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if (iframe!= null) iframe.dispose();
				iframe = new RequestTransferController().getFrame();
				view.addFrame(iframe);
			}
		});
	}
	private void doSystem(){
		view.doSystem(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if (iframe!= null) iframe.dispose();
				iframe = new SystemController().getFrame();
				view.addFrame(iframe);
			}
		});
	}
	private void doExit(){
		view.doExit(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				frame.dispose();
			}
		});
	}

}
